Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - [Risolto] gestione clipboard su windows
Forum - C/C++ - [Risolto] gestione clipboard su windows

Avatar
Metal (Normal User)
Newbie


Messaggi: 16
Iscritto: 04/04/2011

Segnala al moderatore
Postato alle 12:18
Lunedì, 04/04/2011
cercando con google ho trovato questo codice per gestire la clipboard in windows:

Codice sorgente - presumibilmente Delphi

  1. #include <windows.h>
  2.  
  3. /* Copy input to Windows clipboard
  4.  * Data lines must be terminated by the CR LF pair (0xD,0xA)
  5.  * data in: line1CRLFline2CRLFline3CRLF --- Caller must format
  6.  * "this is a line\n" is not acceptable,
  7.  * "this is a line\r\n" is acceptable.
  8.  * If clipboard data shows square empty boxes at line ends in Windows,
  9.  * it is because lines are terminated by \n only.
  10. */
  11. int clipput(char *toclipdata)
  12. {
  13.         char far *buffer;
  14.         int bytes;
  15.  
  16.         HGLOBAL clipbuffer;
  17.  
  18.     // Set data buffer length to accomodate toclipdata
  19.         bytes = strlen(toclipdata);
  20.  
  21.     // Peform the transfer to clipboard magic
  22.         OpenClipboard(NULL);
  23.         EmptyClipboard();
  24.         clipbuffer = GlobalAlloc(GMEM_DDESHARE,bytes+1);
  25.         buffer = (char far*)GlobalLock(clipbuffer);
  26.  
  27.         if (buffer == NULL)
  28.                 return GetLastError() * -1; // Do what you want to signal error
  29.  
  30.         strcpy(buffer,toclipdata);
  31.  
  32.         GlobalUnlock(clipbuffer);
  33.         SetClipboardData(CF_TEXT,clipbuffer);
  34.         CloseClipboard();
  35.  
  36.     // Return byte count
  37.         return bytes; // non-negative value is success.
  38. }



la mia domanda è: a cosa serve quella variabile buffer? perché a parte salvarci il puntatore ritornato da GlobalLock(...), non vedo quale altra utilità abbia, ma se provo a toglierla la funzione non funziona (lol) più...


_______________________________________________________________

EDIT: me ne sono reso solo oggi pensandoci un po' meglio, mi sento un coglione xD ho messo risolto

Ultima modifica effettuata da Metal il 07/04/2011 alle 15:15
PM